<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
    // 解构赋值是对赋值运算符的扩展
    // 针对:数组和对象的操作
    // 优点:代码书写简洁易读

    /**      对象        */
        // 完全解构
    let node = {
            name: 'jack',
            age: 21,
        }

    let {name, age} = node
    console.log(name, age)

    // 部分解构
    let obj = {
        a: {name: '张三'},
        b: [1, 2, 3],
        c: 'hello world'
    }

    // let {a} = obj
    // console.log(a)
    // 使用剩余运算符
    let {a, ...res} = obj
    console.log(res)

    /**      数组        */
    let arr = [1, 2, 3]
    let [x, y, z] = arr
    console.log(x, y, z)

    // 可嵌套
    let arr2 = [1, [2], 3]
    let [q, [w], e] = arr2
    console.log(q, w, e)

    let cart = {
        wheel: 4,
        set(newVal) {
            if (newVal < this.wheel) {
                throw new Error('轮子数太少了')
            }
            this.wheel = newVal
        },
        get() {
            return this.wheel
        }
    }

    cart.set(8)
    console.log(cart.get())

    // 扩展功能的用法
    const myName = 'a'
    const obj2 = {
        isSHow: true,
        [name + 'bc']: 123,
        ['f' + myName]() {
            console.log(this)
        }
    }
    console.log(obj2)

    // Object.is() 判断两个值是否相同 ,不会做类型转换
    console.log(Object.is(NaN, NaN))   // true   NaN的比较最常用is来比较 ，其他用===来比较
    console.log(Object.is({age: 21}, {age: '21'}))   // false
    console.log(Object.is({name:'jack',age: 21}, {name:'jack',age: 21}))   // false

    // assign 用于对象属性合并   浅拷贝!!
   let newObj = Object.assign({},{a:1},{b:2})
    console.log(newObj)
</script>
</body>
</html>
